// 本文件由自动工具 proto.py 自动生成，请勿修改
// filename test_csbuf.go
// package test

package test

import (
	"git.oschina.net/wint/go-csbuf/csbuf"
)

// message Test
type Test struct {
	T1 uint8 `json:"t1"`
	T_2 uint32 `json:"t_2"`
	T3_ string `json:"t3_"`
	T4 []uint32
}

func (m *Test) GetProtoId() uint16 {
	return 1001
}

func (m *Test) Marshal(w *csbuf.CsbufParser) {
	w.SetUint8(m.T1, 1)
	w.SetUint32(m.T_2, 2)
	w.SetString(m.T3_, 3)
	w.SetArray(uint8(len(m.T4)), 4)
	for _, v := range m.T4 {
		w.SetUint32(v, 0)
	}
}

func (m *Test) Unmarshal(r *csbuf.CsbufParser) {
	m.T1 = r.GetUint8(1)
	m.T_2 = r.GetUint32(2)
	m.T3_ = r.GetString(3)
	countT4 := int(r.GetArray(4))
	for i := 0; i < countT4; i++ {
		m.T4 = append(m.T4, r.GetUint32(0))
	}
}

func NewTest() csbuf.CsbufMessage {
	return &Test{}
}

// message t2
type T2 struct {
	T1 uint8 `json:"t1"`
	T3 int16 `json:"t3"`
}

func (m *T2) GetProtoId() uint16 {
	return 1002
}

func (m *T2) Marshal(w *csbuf.CsbufParser) {
	w.SetUint8(m.T1, 1)
	w.SetInt16(m.T3, 2)
}

func (m *T2) Unmarshal(r *csbuf.CsbufParser) {
	m.T1 = r.GetUint8(1)
	m.T3 = r.GetInt16(2)
}

func NewT2() csbuf.CsbufMessage {
	return &T2{}
}

